
/**
 * Copyright 2009 cestum.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
package org.waveprotocol.wave.model.document.operation.impl {
import mx.collections.ArrayCollection;



import org.goverla.collections.ArrayList;

import org.waveprotocol.wave.model.document.operation.AttributesUpdate;

import org.waveprotocol.wave.model.document.operation.util.ImmutableAttributesUpdateMap;

import org.waveprotocol.wave.model.document.operation.util.UpdateMap;

public class AttributesUpdateImpl extends ImmutableAttributesUpdateMap  implements AttributesUpdate {
	
	public static var EMPTY_MAP:AttributesUpdateImpl= new AttributesUpdateImpl(null);
	
	public static function of(a:String, b:String, c:String):AttributesUpdateImpl {
		return new AttributesUpdateImpl(ImmutableAttributesUpdateMap.of([a,b,c]));
	}
	
	
	public static function ofArray(a:Array):AttributesUpdateImpl {
		return new AttributesUpdateImpl(ImmutableAttributesUpdateMap.of(a));
	}
	
	public function AttributesUpdateImpl(updates:ArrayList) {
		super(updates);
	}
	
	override protected function createFromList(updates:ArrayList):AttributesUpdate {
		return new AttributesUpdateImpl(updates);
	}
	
	public static function fromSortedUpdates(sortedUpdates:ArrayList):AttributesUpdate {
		checkUpdatesSorted(sortedUpdates);
		return fromSortedUpdatesUnchecked(sortedUpdates);
	}
	
	public static function fromSortedUpdatesUnchecked(
		sortedUpdates:ArrayList):AttributesUpdateImpl {
		return new AttributesUpdateImpl(sortedUpdates);
	}
	
//	public static function fromUnSortedUpdates(unSortedUpdates:ArrayList):AttributesUpdate {
//		List<AttributeUpdate> sorted = new ArrayList<AttributeUpdate>(unsortedAttributes);
//		Collections.sort(sorted, comparator);
//		// Use the checked variant here to check for duplicates.
//		return fromSortedUpdates(sorted);
//	}
	
	
	override public function composeWith(mutation:AttributesUpdate):AttributesUpdate {
		return AttributesUpdate(super.composeWith(mutation));
	}
	
	
	override public function exclude(keys:ArrayCollection):AttributesUpdate {
		return AttributesUpdate(super.exclude(keys));
	}
	
}
}